<?php
/**
 * Created by PhpStorm.
 * User: 子不语
 * Date: 2016/5/27
 * Time: 12:35
 */
include_once("../inc/conn.php");
include_once("../inc/function.php");
//if($_REQUEST['type']=='alipay')
$arr=array('alipay','wx','hj','','wx_qrcode');
$type=$_REQUEST['pay_web'];



//include_once '../payment/'.$type.'.php';

$Pay=new $type();
file_put_contents('test.txt',var_export($_REQUEST,true) ,FILE_APPEND);
if($_REQUEST['BillNo']){
    if($res=$Pay->respond()!==true) {
        die($res);
    }
    $payid=trim($_REQUEST['BillNo']);
    $orderNo=trim($_REQUEST['Result']);
    $sql = "call web_payonline_topay('{$payid}','{$orderNo}')";
    //WriteLog($sql);
    $arr = $db->Mysqli_Multi_Query($sql);
    $ret = $arr[0][0]["result"];
    switch($ret)
    {
        case '-1':
            $msg = "系统错误，请联系客服!";
            break;
        case '0':
            $msg = "充值成功!";
            break;
        case '1':
            $msg = "订单不存在!请联系客服!";
            break;
        case '2':
            $msg = "该订单已充值过了!";
            break;
        default:
            $msg = "未知错误，请联系客服!";
            break;
    }
    header("location:http://120.76.116.167/member.php");
    //$msg .= "订单号:" . $payid . ",交易流水号:" . $orderNo;
    //die($msg);

}
//检测登录
//login_check();
header("Content-Type: text/html; charset=UTF-8");

//取得订单号
$PayRMB = floatval($_REQUEST['money']);
$uid=intval($_REQUEST['uid']);

if($PayRMB == 0)
{
    echo "请选择正确的充值金额!";
    exit;
}
$PayPoint = $PayRMB * 1000;
$ip = usersip();
$sql = "call web_payonline_addorder({$uid},{$PayRMB},{$PayPoint},'{$ip}')";
//WriteLog($sql);
$arr = $db->Mysqli_Multi_Query($sql);
$OrderID = $arr[0][0]["OrderID"];
if(strlen($OrderID) < 3)
{
    echo "取充值订单失败!";
    exit;
}

$res=$Pay->pay($OrderID,$PayRMB );